home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 255_01 / gpball.asm < prev    next >
Assembly Source File  |  1988-03-28  |  18KB  |  518 lines

  1.           page   80,132
  2.           page
  3. ;
  4. ;       EGA Graphic Primitive for Turbo Pascal 3.01A, Version 01MAR86.
  5. ;       (C) 1986 by Kent Cedola, 2015 Meadow Lake Ct., Norfolk, VA, 23518
  6. ;
  7. ;       The algorithm for drawing a circle (below) was from an article in
  8. ;       Dr. Dobb's Journal, December 1983, pp. 19 by Michael T. Enright.
  9. ;
  10. ;       I converted it from BASIC source (from above) to assembler for high
  11. ;       speed plotting and added color/shading fill and clipping code.
  12. ;
  13.  
  14. radius    equ    4
  15.  
  16. xcoor1    equ    -2                    ; X coordinate (left half)
  17. xcoor2    equ    -4                    ; X coordinate (right half)
  18. ycoor1    equ    -6                    ; Location of Y graphic row, contains
  19. ycoor2    equ    -8                    ;   ... row byte offset.
  20.  
  21. xc        equ    -10
  22. yc        equ    -12
  23.  
  24. xd        equ    -14                   ; Long integer (32 bits)
  25. yd        equ    -18                   ; Long integer (32 bits)
  26. zx        equ    -22                   ; Long integer (32 bits)
  27. zy        equ    -26                   ; Long integer (32 bits)
  28. tx        equ    -30                   ; Long integer (32 bits)
  29. ty        equ    -34                   ; Long integer (32 bits)
  30. tb        equ    -38                   ; Long integer (32 bits)
  31. er        equ    -42                   ; Long integer (32 bits)
  32. atx       equ    -46                   ; Long integer (32 bits)
  33. aty       equ    -50                   ; Long integer (32 bits)
  34. atb       equ    -54                   ; Long integer (32 bits)
  35.  
  36. xf1       equ    -58
  37. xf2       equ    -60
  38. yf1       equ    -62
  39. yf2       equ    -64
  40.  
  41. needed    equ    68                    ; Amount of temporary space needed
  42.  
  43. dgroup    group  _data
  44.  
  45. _data     segment word public 'data'
  46.           assume ds:dgroup
  47.  
  48.           extrn  _gdtype:byte
  49.           extrn  _gdmaxcol:word,_gdmaxrow:word
  50.           extrn  _gdcolor:byte,_gdmerge:byte,_gdaspc1:word,_gdaspc2:word
  51.           extrn  _gdcur_x:word,_gdcur_y:word
  52.           extrn  _gdwd_x1:word,_gdwd_x2:word,_gdwd_x3:word
  53.           extrn  _gdwd_y1:word,_gdwd_y2:word,_gdwd_y3:word
  54.           extrn  _gdvw_x1:word,_gdvw_x2:word,_gdvw_x3:word
  55.           extrn  _gdvw_y1:word,_gdvw_y2:word,_gdvw_y3:word
  56.           extrn  _gdshade:word
  57.           extrn  _gdc_flg:byte,_gds_flg:byte,_gdw_flg:byte
  58.  
  59. _data     ends
  60.  
  61. _text     segment byte public 'code'
  62.  
  63.           assume cs:_text,ds:dgroup
  64.           public _gpball
  65. _gpball   proc   near
  66.  
  67.           push   bp
  68.           mov    bp,sp
  69.           sub    sp,needed             ; Reserve space for temp. variables
  70.  
  71.           push   si
  72.           push   di
  73.  
  74.           mov    _GDC_FLG,2            ; Set clipping flag
  75.  
  76. ;    Compute AE = R (save in BX for later)
  77.  
  78.           mov    ax,[bp+radius]        ; Load user specified radius
  79.           or     ax,ax                 ; If radius is zero, make it 1
  80.           jnz    notzero               ;
  81.           inc    ax                    ;
  82. notzero:
  83.           mov    bx,ax                 ; Copy to BX (AX used later)
  84.           mov    ax,_GDCUR_X
  85.           sub    ax,bx
  86.           cmp    ax,_GDVW_X2
  87.           jbe    next1
  88.           jmp    theend
  89. next1:
  90.           mov    [bp+xc],ax
  91.           add    ax,bx
  92.           add    ax,bx
  93.           cmp    ax,_GDVW_X1
  94.           jae    next2
  95.           jmp    theend
  96. next2:
  97.  
  98. ;    Compute BE = (R * _GDASPC1 / _GDASPC2) (save in DX for later)
  99.  
  100.           mov    ax,bx                 ; Start with R (AE above)
  101.           mul    _GDASPC1           ; Compute the real Y radius from the
  102.           div    _GDASPC2           ;      the defined screen aspects
  103.           mov    dx,ax                 ; Copy to DX (temp save area)
  104.  
  105. ;    Compute the Y coordinate graphic row offset.
  106.  
  107.           mov    cx,_GDCUR_Y           ; Compute the upper and lower row for
  108.           sub    cx,ax                 ;   line clipping logic
  109.           cmp    cx,_GDVW_Y2           ;
  110.           jbe    next3
  111.           jmp    theend
  112. next3:
  113.           mov    [bp+yc],cx
  114.           mov    [bp+yf1],cx           ;   ...
  115.           add    cx,ax                 ;   ...
  116.           add    cx,ax                 ;   ...
  117.           cmp    cx,_GDVW_Y1
  118.           jae    next4
  119.           jmp    theend
  120. next4:
  121.           mov    [bp+yf2],cx           ;   ...
  122.  
  123.           mov    _GDC_FLG,0            ; Clear clipping flag
  124.  
  125.           shl    ax,1                  ; Compute the graphic segment offset
  126.           shl    ax,1                  ;   for the Y radius length
  127.           add    ax,dx                 ;   ...
  128.           mov    si,ax                 ; Copy to SI (temp save area)
  129.  
  130.           mov    ax,_GDCUR_Y           ; Compute the graphic segment offset
  131.           shl    ax,1                  ;   for the current row
  132.           shl    ax,1                  ;   ... = A000 + (80 * Y) / 16;
  133.           add    ax,_GDCUR_Y           ;   ...
  134.           add    ax,0A000h             ;   ...
  135.           sub    ax,si                 ; Init the top and bottow y coordinates
  136.           mov    [bp+ycoor1],ax        ;   ...
  137.           add    ax,si                 ;   ...
  138.           add    ax,si                 ;   ...
  139.           mov    [bp+ycoor2],ax        ;   ...
  140.  
  141. ;    Compute the X coordinate graphic bit offset.
  142.  
  143.           mov    ax,_GDCUR_X           ; Compute the column byte offset
  144.           mov    [bp+xf1],ax           ; Save the left and right column numbers
  145.           mov    [bp+xf2],ax           ;   for clipping logic
  146.  
  147. ;    Compute XD = BE * BE
  148.  
  149.           mov    cx,dx                 ; Save BE for later (in CX)
  150.           mov    ax,dx                 ; Must use AX for multiply
  151.           mul    dx                    ; BE * BE (AX * DX)
  152.           mov    [bp+xd],ax            ; Save XD
  153.           mov    [bp+xd-2],dx          ;   ...
  154.  
  155. ;    Compute DX = 2 * BE * BE (or XD * 2)
  156.  
  157.           shl    ax,1                  ; Long shift left for multiply
  158.           rcl    dx,1                  ;   ...
  159.           mov    [bp+zx],ax            ; Save DX
  160.           mov    [bp+zx-2],dx          ;   ...
  161.  
  162. ;    Compute DY = 2 * AE * AE
  163.  
  164.           mov    ax,bx                 ; Move current AE to AX
  165.           mul    bx                    ;   ... (AE * AE)
  166.           push   dx                    ; Save the value (AE * AE) for later
  167.           push   ax                    ;   ...
  168.           shl    ax,1                  ; Compute AE * AE * 2 (shift left)
  169.           rcl    dx,1                  ;   ...
  170.           mov    [bp+zy],ax            ; Save DY
  171.           mov    [bp+zy-2],dx          ;   ...
  172.  
  173. ;    Compute YD = (2 * BE - 1) * AE * AE
  174.  
  175.           pop    ax
  176.           shl    cx,1                  ; Compute BE * 2
  177.           dec    cx                    ; Compute BE * 2 - 1
  178.           mul    cx                    ; Compute (BE * 2 - 1) * AE
  179.           mov    [bp+yd],ax            ; Save what we have so far
  180.           mov    [bp+yd-2],dx          ;   ...
  181.           pop    ax                    ; Compute (BE * 2 - 1) * AE * AE
  182.           mul    cx                    ;   ...
  183.           add    [bp+yd-2],ax          ;   ...
  184.  
  185. ;    Compute ER = 0
  186.  
  187.           xor    ax,ax                 ; Clear AX to clear ER
  188.           mov    [bp+er],ax            ;   ...
  189.           mov    [bp+er-2],ax          ;   ...
  190.  
  191. ;    Setup the EGA to perform graphics
  192.  
  193.           mov    dx,03CEh              ; Load EGA graphic controller port addr.
  194.           mov    ah,_GDMERGE           ; Load current merge setting
  195.           mov    al,3                  ; Merge register is number three
  196.           out    dx,ax                 ; Set the EGA's merge register
  197.           mov    ax,0205h              ; Load write mode number two
  198.           out    dx,ax                 ; Set the EGA's mode register
  199.           mov    al,8                  ; Load the mask register number
  200.           out    dx,al                 ; Just postion EGA's controller to it
  201.  
  202.           call   plotpnts              ; Plot the first set of points
  203.  
  204. next_x:
  205.           mov    cx,-1
  206.  
  207.           mov    ax,[bp+er]            ; Compute TX = ER + XD
  208.           mov    dx,[bp+er-2]          ;   ...
  209.